/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rgenerator;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author Alexandru Stefan
 */
public class Gui extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

    /**
     * Creates new form Gui
     */
    public Gui() {
        initComponents();
         ImageIcon icon=new ImageIcon("src/res/logoClassFiler.png");
        Image inagine=icon.getImage();
        
//        if (SystemTray.isSupported()) {
//            SystemTray tray=SystemTray.getSystemTray();
//            
//            TrayIcon trayicon=new TrayIcon(inagine);
//            
//            try{
//            tray.add(trayicon);
//            System.out.println("icon pus");
//            }
//            catch (Exception ex) {
//                
//            }
//           
//        }
//        else{
//        System.out.println("System try not supported");
//        }
        
        
        
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        DisplayMode dm=gs.getDisplayMode();
        int width=dm.getWidth();
        int height=dm.getHeight();
                
        
        this.setLocation(new Point((width-this.getWidth())/2, (height-this.getHeight())/2));
        
        
       
        this.setIconImage(inagine);
        aboutWindow.setIconImage(inagine);
        
        obiectSerial=serialisation.readFile();
       
        packName.setText(obiectSerial.getPackName());
        className.setText(obiectSerial.getMainClassName());
        inputFolder.setText(obiectSerial.getInputFolderPath());
        outPutFolder.setText(obiectSerial.getOutPutFolderPath());
        getModeOn.setSelected(obiectSerial.isGetterMode());
        doubleSlashedOn.setSelected(obiectSerial.isDoubleSlashed());
        slashInFronOn.setSelected(obiectSerial.isSlashInFront());
        backSlashedOn.setSelected(obiectSerial.isBackSlashed());
        saveLocation=obiectSerial.getSaveLoc();
        loadLocation=obiectSerial.getLoadLoc();
        
        
        
       // outTextArea.setEnabled(false);
        changePreviewText();
        
        
        //event de inchidere
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent evt) {
             serialisation=new Serialization();
             obiectSerial=new SerialObject(packName.getText(), className.getText(), inputFolder.getText(), outPutFolder.getText(), getModeOn.isSelected(), doubleSlashedOn.isSelected(), slashInFronOn.isSelected(), backSlashedOn.isSelected(), saveLocation, loadLocation);
             serialisation.writeFile(obiectSerial);
            }
        });
        
    }
    
    private void refreshDisplay(){
        packName.setText(obiectSerial.getPackName());
        className.setText(obiectSerial.getMainClassName());
        inputFolder.setText(obiectSerial.getInputFolderPath());
        outPutFolder.setText(obiectSerial.getOutPutFolderPath());
        getModeOn.setSelected(obiectSerial.isGetterMode());
        doubleSlashedOn.setSelected(obiectSerial.isDoubleSlashed());
        slashInFronOn.setSelected(obiectSerial.isSlashInFront());
        backSlashedOn.setSelected(obiectSerial.isBackSlashed());
        saveLocation=obiectSerial.getSaveLoc();
        loadLocation=obiectSerial.getLoadLoc();
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCheckBox2 = new javax.swing.JCheckBox();
        jMenu2 = new javax.swing.JMenu();
        alegeFisier = new javax.swing.JFileChooser();
        saveDialog = new javax.swing.JFileChooser();
        aboutWindow = new javax.swing.JFrame();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        inputFolder = new javax.swing.JTextField();
        InputBtn = new javax.swing.JButton();
        outPutFolder = new javax.swing.JTextField();
        OutPutBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        outTextArea = new javax.swing.JTextArea();
        GenerateButton = new javax.swing.JButton();
        getModeOn = new javax.swing.JCheckBox();
        doubleSlashedOn = new javax.swing.JCheckBox();
        slashInFronOn = new javax.swing.JCheckBox();
        packName = new javax.swing.JTextField();
        packNameLabel = new javax.swing.JLabel();
        mainclasslabel = new javax.swing.JLabel();
        className = new javax.swing.JTextField();
        backSlashedOn = new javax.swing.JCheckBox();
        inxoText = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        SaveMenuItem = new javax.swing.JMenuItem();
        LoadMenuItem = new javax.swing.JMenuItem();
        AboutMenuItem = new javax.swing.JMenu();

        jCheckBox2.setText("jCheckBox2");

        jMenu2.setText("jMenu2");

        alegeFisier.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
        alegeFisier.setCurrentDirectory(new java.io.File("D:\\___PORTOFOLIU_ALEXE\\projects_AS3\\BUZZZZZ"));
        alegeFisier.setDialogTitle("Select folder to classify:");
        alegeFisier.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);

        saveDialog.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
        saveDialog.setBackground(new java.awt.Color(255, 255, 204));

        aboutWindow.setTitle("About");
        aboutWindow.setBounds(new java.awt.Rectangle(0, 0, 300, 160));
        aboutWindow.setName("About");
        aboutWindow.setResizable(false);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/logoClassFiler.png"))); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Originally created by Alexandru Stefan");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("...waiting for revision");

        javax.swing.GroupLayout aboutWindowLayout = new javax.swing.GroupLayout(aboutWindow.getContentPane());
        aboutWindow.getContentPane().setLayout(aboutWindowLayout);
        aboutWindowLayout.setHorizontalGroup(
            aboutWindowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        aboutWindowLayout.setVerticalGroup(
            aboutWindowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aboutWindowLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(0, 25, Short.MAX_VALUE))
        );

        aboutWindow.getAccessibleContext().setAccessibleParent(outTextArea);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setLocationByPlatform(true);
        setResizable(false);
        setType(java.awt.Window.Type.POPUP);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                windowClosedEvent(evt);
            }
        });

        inputFolder.setEditable(false);
        inputFolder.setText("D:/Lucru_Alex/CLASA 0/v.0.01.01/bin");

        InputBtn.setText("Input");
        InputBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InputBtnActionPerformed(evt);
            }
        });

        outPutFolder.setEditable(false);

        OutPutBtn.setText("OutPut");
        OutPutBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutPutBtnActionPerformed(evt);
            }
        });

        outTextArea.setColumns(20);
        outTextArea.setEditable(false);
        outTextArea.setRows(5);
        outTextArea.setText("package alex.stf {\npublic class R {\npublic static const name:Resurs=new Resurs();\npublic static const prop:String=\"name/\"\n}\n}\n\n\npackage alex.stf {\npublic class Resurs {\npublic var property:String=\"name/\"\n}\n}");
        outTextArea.setToolTipText("preview\n");
        jScrollPane1.setViewportView(outTextArea);

        GenerateButton.setBackground(new java.awt.Color(204, 255, 255));
        GenerateButton.setText("Generate");
        GenerateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GenerateButtonActionPerformed(evt);
            }
        });

        getModeOn.setLabel("getter mode");
        getModeOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getModeOnActionPerformed(evt);
            }
        });

        doubleSlashedOn.setText("double slash");
        doubleSlashedOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doubleSlashedOnActionPerformed(evt);
            }
        });

        slashInFronOn.setText("slash in front");
        slashInFronOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                slashInFronOnActionPerformed(evt);
            }
        });

        packName.setText("jTextField3");
        packName.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                caretPackUpate(evt);
            }
        });

        packNameLabel.setText("package name:");

        mainclasslabel.setText("main class:");

        className.setText("R");
        className.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                caretUpdateMain(evt);
            }
        });

        backSlashedOn.setText("back slahed");
        backSlashedOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backSlashedOnActionPerformed(evt);
            }
        });

        inxoText.setText("generate a new class package");

        jMenu1.setText("File");

        SaveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        SaveMenuItem.setText("Save Settings");
        SaveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(SaveMenuItem);

        LoadMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        LoadMenuItem.setText("Load Settings");
        LoadMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(LoadMenuItem);

        jMenuBar1.add(jMenu1);

        AboutMenuItem.setText("About");
        AboutMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                AboutMenuItemMouseClicked(evt);
            }
        });
        AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutMenuItemActionPerformed(evt);
            }
        });
        jMenuBar1.add(AboutMenuItem);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(GenerateButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(packNameLabel)
                        .addGap(18, 18, 18)
                        .addComponent(packName)
                        .addGap(18, 18, 18)
                        .addComponent(mainclasslabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(className))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(outPutFolder, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(inputFolder, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(OutPutBtn)
                            .addComponent(InputBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(getModeOn)
                        .addGap(18, 18, 18)
                        .addComponent(doubleSlashedOn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(35, 35, 35)
                        .addComponent(slashInFronOn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(backSlashedOn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(inxoText, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(packName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(packNameLabel)
                    .addComponent(mainclasslabel)
                    .addComponent(className, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(InputBtn))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(outPutFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(OutPutBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(doubleSlashedOn)
                    .addComponent(slashInFronOn)
                    .addComponent(backSlashedOn)
                    .addComponent(getModeOn, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(inxoText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(GenerateButton)
                .addContainerGap())
        );

        getModeOn.getAccessibleContext().setAccessibleName("getMode");
        doubleSlashedOn.getAccessibleContext().setAccessibleName("doubleSlashMode");
        slashInFronOn.getAccessibleContext().setAccessibleName("slashInFrontMode");
        packNameLabel.getAccessibleContext().setAccessibleName("packageName");
        className.getAccessibleContext().setAccessibleName("MainClassName");

        pack();
    }// </editor-fold>//GEN-END:initComponents

     private String ot="";
     private String slashinfront="";
     private String slashes="";
      //astea sunt doar e preview:
     private String typeOne="";
     private String typeTwo="";
     private String typeThree="";
     
     private String saveLocation="C:/";
     private String loadLocation="D:/";
     
     
     private SerialObject obiectSerial;
     private Serialization serialisation=new Serialization();
     private File lastSavedFile=new File("ClassFileR_settings.xml");
    
    private void changePreviewText(){
      
        ot="";
        outTextArea.setText(ot);
        
        String np=packName.getText();
        
        String verifiers[]={"/", "+", "@", "!", "$", ")", "(", "*", "%", ";", "=", ":", "\"", "'", ">", "<", "?", "]", "[", "{", "}", "|", "\\"};
        
        for (int i = 0; i < verifiers.length; i++) {
            if (np.contains(verifiers[i])) {
                inxoText.setText("incorect argument in pack name.");
                enableInput(false);
                return;
            }
            else if(className.getText().contains(verifiers[i])){
                 inxoText.setText("incorect argument in main class name.");
                 enableInput(false);
                 return;
            }
            else if(className.getText().contains(".")){
                 inxoText.setText("incorect argument in main class name.");
                 enableInput(false);
                 return;
            }
        }
        
        
//        if (!inputFolder.getText().contains("/")) {
//             enableInput(false);
//             return;
//        }
        
        inxoText.setText("OK... 'till now!");
        enableInput(true);
      
        
        
      
        if (backSlashedOn.isSelected()) {
            slashes="\\";
        }
        else{
            slashes="/";
        }
      
        if (doubleSlashedOn.isSelected()) {
            slashes+=slashes;
        }
      
        if (slashInFronOn.isSelected()) {
            slashinfront=slashes;
        }
      
     
      
        if (getModeOn.isSelected()) {
            typeOne="  public var foldername:FolderNameClass=new FolderNameClass(); \n";
			typeThree=typeOne;
            typeTwo="  public function get filename():String{ \n ";
            typeTwo+="   return \""+slashinfront+"foldername"+slashes+"filename.txt"+"  \"";
			typeTwo+="\n";
			typeTwo+="   }\n";
        }
		else{
			typeOne="  public var foldername:FolderNameClass=new FolderNameClass(); \n";
			typeThree="   public static const:FolderNameClass=new FolderNameClass(); \n";
                        typeTwo="   public var fileName:String= \""+slashinfront+"foldername"+slashes+"filename.txt"+"  \" \n";
		}
      
      ot+="package "+packName.getText()+" { \n";
      ot+=" public class "+className.getText()+"{ \n";
	  ot+=typeThree;
	  ot+=typeTwo;
      ot+=" } \n";
      ot+="} \n";
      
      ot+="package "+packName.getText()+" { \n";
      ot+=" public class "+"FolderNameClass "+"{ \n";
	  ot+=typeOne;
	  ot+=typeTwo;
      ot+=" } \n";
      ot+="} \n";
      
      outTextArea.setText(ot);
     
    }
    
    private void enableInput(Boolean param){
        GenerateButton.setEnabled(param);
        inputFolder.setEnabled(param);
        outPutFolder.setEnabled(param);
        InputBtn.setEnabled(param);
        OutPutBtn.setEnabled(param);
        getModeOn.setEnabled(param);
        doubleSlashedOn.setEnabled(param);
        slashInFronOn.setEnabled(param);
        backSlashedOn.setEnabled(param);
    }
    
    
    private void SaveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveMenuItemActionPerformed
        // TODO add your handling code here:
        
        System.out.println("save setting");
         
       saveDialog.setDialogTitle("Save your current settings");  
       saveDialog.setCurrentDirectory(new File(saveLocation));
       saveDialog.setSelectedFile(lastSavedFile);
       
       
        int returnval=saveDialog.showSaveDialog(outTextArea);
        
       
       
        
       // saveDialog.setSelectedFile(xmlFile);
        
        if (returnval==JFileChooser.CANCEL_OPTION) {
            saveLocation=saveDialog.getCurrentDirectory().toURI().getPath();
            System.out.println("a renuntat");
        }
        
        if (returnval==JFileChooser.APPROVE_OPTION) {
            System.out.println("save zmtf  ");
            //savlam locatia curenta
            saveLocation=saveDialog.getCurrentDirectory().toURI().getPath();
             
                    
             
                    try{
                        
                        int choice=0;
                         File xmlFile=new File(saveDialog.getCurrentDirectory().getPath()+"/"+saveDialog.getName(saveDialog.getSelectedFile()));
                         
                         if (xmlFile.exists()) {
                           choice= JOptionPane.showConfirmDialog(outTextArea, "Overwrite existing file?", "Confirm overwrite", JOptionPane.YES_NO_OPTION);
                         }
                         
                         if (choice==0) {
                             FileWriter outFile = new FileWriter(xmlFile);
                             lastSavedFile=xmlFile;
                                try (PrintWriter out = new PrintWriter(outFile)) {
                                    out.println("<classfilersetting>");
                                        out.println("<packname>"+packName.getText()+"</packname>");
                                        out.println("<classname>"+className.getText()+"</classname>");
                                        out.println("<inputfolder>"+inputFolder.getText()+"</inputfolder>");
                                        out.println("<outpufolder>"+outPutFolder.getText()+"</outpufolder>");
                                        out.println("<gettermode>"+getModeOn.isSelected()+"</gettermode>");
                                        out.println("<slashinfront>"+slashInFronOn.isSelected()+"</slashinfront>");
                                        out.println("<backslash>"+backSlashedOn.isSelected()+"</backslash>");
                                        out.println("<doubleslash>"+doubleSlashedOn.isSelected()+"</doubleslash>");
                                    out.println("</classfilersetting>");
                                }
                             System.out.println("writing and overWriting");
                        }
                         
                         System.out.println(choice);
                         
                        
                    }
                    catch(HeadlessException | IOException ex){
                            System.out.println("some error occured");
                    }
        }
        
        
    }//GEN-LAST:event_SaveMenuItemActionPerformed

    
    
    
    
    private void OutPutBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutPutBtnActionPerformed
        // TODO add your handling code here:
        int returnVal=alegeFisier.showDialog(mainclasslabel, "Select");
       
        alegeFisier.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        
        if (returnVal==JFileChooser.APPROVE_OPTION) {
            String caleuri=alegeFisier.getSelectedFile().toURI().getPath();
            outPutFolder.setText(caleuri);
        }
        
    }//GEN-LAST:event_OutPutBtnActionPerformed

    private void InputBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InputBtnActionPerformed
        // TODO add your handling code here:
        alegeFisier.setCurrentDirectory(new File("D:/"));
        
         int returnVal=alegeFisier.showDialog(mainclasslabel, "Select");
       
        alegeFisier.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        
        if (returnVal==JFileChooser.APPROVE_OPTION) {
            String caleuri=alegeFisier.getSelectedFile().toURI().getPath();
                    //caleuri+"/"+alegeFisier.getCurrentDirectory().getName();
            inputFolder.setText(caleuri);
        }
        
    }//GEN-LAST:event_InputBtnActionPerformed

    private void getModeOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getModeOnActionPerformed
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_getModeOnActionPerformed

    private void doubleSlashedOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doubleSlashedOnActionPerformed
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_doubleSlashedOnActionPerformed

    private void slashInFronOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_slashInFronOnActionPerformed
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_slashInFronOnActionPerformed

    private void backSlashedOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backSlashedOnActionPerformed
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_backSlashedOnActionPerformed

    private void caretPackUpate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_caretPackUpate
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_caretPackUpate

    private void caretUpdateMain(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_caretUpdateMain
        // TODO add your handling code here:
        changePreviewText();
    }//GEN-LAST:event_caretUpdateMain

    private void GenerateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GenerateButtonActionPerformed
        // TODO add your handling code here:
        Stringers type=new Stringers();
        type.inputFolder=this.inputFolder.getText();
        type.outPutFolder=this.outPutFolder.getText();
        type.mainClassName=this.className.getText();
        type.packageName=this.packName.getText();
        type.doubleSlashed=this.doubleSlashedOn.isSelected();
        type.slashInFront=this.slashInFronOn.isSelected();
        type.backSlashed=this.backSlashedOn.isSelected();
        type.setGetterMode(this.getModeOn.isSelected());
        
        
        
        FilesGenerator generate=new FilesGenerator(type, new FileGenerationEvent() {

            @Override
            public void generatingStart() {
                //throw new UnsupportedOperationException("Not supported yet.");
              enableInput(false);
            }

            @Override
            public void generatingStopped() {
                //throw new UnsupportedOperationException("Not supported yet.");
               JOptionPane.showMessageDialog(outTextArea, "files created in ::  "+outPutFolder.getText());
               enableInput(true);
            }
        });
    }//GEN-LAST:event_GenerateButtonActionPerformed

    private void windowClosedEvent(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosedEvent
        // TODO add your handling code here:
        System.out.println("window closed");
    }//GEN-LAST:event_windowClosedEvent

    private void LoadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadMenuItemActionPerformed
        // TODO add your handling code here:
        
        saveDialog.setCurrentDirectory(new File(loadLocation));
        saveDialog.setDialogTitle("Open settings file");  
        saveDialog.setSelectedFile(lastSavedFile);
        
        int returnVal=saveDialog.showOpenDialog(outTextArea);
        
        if (returnVal==JFileChooser.APPROVE_OPTION) {
           loadLocation=saveDialog.getCurrentDirectory().toURI().getPath();
            
           try{
            
               if (saveDialog.getSelectedFile().exists()) {
                   obiectSerial=new SettingsRead().read(saveDialog.getSelectedFile(), saveLocation, loadLocation, obiectSerial);
                   refreshDisplay();
               }
               else{
                     JOptionPane.showMessageDialog(outTextArea, "file not found");
               }
               
           }
           catch(Exception ex){
               JOptionPane.showMessageDialog(outTextArea, "error occured");
           }
           
        }
        
    }//GEN-LAST:event_LoadMenuItemActionPerformed

    private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed
        // TODO add your handling code here:
        System.out.println("the duf");
       // aboutWindow.setVisible(true);
    }//GEN-LAST:event_AboutMenuItemActionPerformed

    private void AboutMenuItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AboutMenuItemMouseClicked
        // TODO add your handling code here:
        System.out.println("the duf");
        aboutWindow.setVisible(true);
        aboutWindow.setBounds(new Rectangle(this.getLocation().x+(this.getWidth()-aboutWindow.getWidth())/2, this.getLocation().y+(this.getHeight()-aboutWindow.getHeight())/2, 300, 160));
       // this.setEnabled(false);
        //aboutWindow.setPreferredSize(new Dimension(200, 200));
       // aboutWindow.pack();
    }//GEN-LAST:event_AboutMenuItemMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Gui().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu AboutMenuItem;
    private javax.swing.JButton GenerateButton;
    private javax.swing.JButton InputBtn;
    private javax.swing.JMenuItem LoadMenuItem;
    private javax.swing.JButton OutPutBtn;
    private javax.swing.JMenuItem SaveMenuItem;
    private javax.swing.JFrame aboutWindow;
    private javax.swing.JFileChooser alegeFisier;
    private javax.swing.JCheckBox backSlashedOn;
    private javax.swing.JTextField className;
    private javax.swing.JCheckBox doubleSlashedOn;
    private javax.swing.JCheckBox getModeOn;
    private javax.swing.JTextField inputFolder;
    private javax.swing.JLabel inxoText;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel mainclasslabel;
    private javax.swing.JTextField outPutFolder;
    private javax.swing.JTextArea outTextArea;
    private javax.swing.JTextField packName;
    private javax.swing.JLabel packNameLabel;
    private javax.swing.JFileChooser saveDialog;
    private javax.swing.JCheckBox slashInFronOn;
    // End of variables declaration//GEN-END:variables
}
